package com.yueqian.sc.bean;

/**
 * 分页实体类
 * 注意：传递的参数只有三个：
 *      totalCount:总条目数
 *      rows:每一页显示的条数
 *      currentPage:当前页
 *      其他：
 *         内部计算
 *      切记：
 *         在封装中，只能通过setter改变数据的值，getter只提供取值
 */
public class PageBean {
    private int totalCount;  //总条目数
    private int rows = 5;  //每一页显示的条数
    private int totalPage;  //总页数
    private int currentPage;  //当前页面页码
    private boolean isFirstPage;  //是否首页
    private boolean isLastPage;  //是否尾页
    private int prePage;  //回到上一页
    private int nextPage2;  //回到下一页
    private int startIndex;//开始索引

    public PageBean() {
    }

    public PageBean(int totalCount, int rows, int currentPage) {
        this.totalCount = totalCount;
        this.rows = rows;
        this.currentPage = currentPage;
        //以下方法可以放在相应的set方法
        //计算总页数
        this.totalPage =(this.totalCount%this.rows==0?0:1)+this.totalCount/this.rows;
        //计算开始索引
        startIndex = (this.currentPage-1)*rows;
        //判断是否是首页
        isFirstPage = currentPage==1?true:false;
        //判断是否是尾页
        isLastPage = currentPage==totalPage?true:false;
        //上一页
        prePage = isFirstPage()?currentPage:currentPage-1;
        //下一页
        nextPage2 = isLastPage()?currentPage:currentPage+1;
        System.out.println("打印分页信息：");
        System.out.println("currentPage:"+this.currentPage);
        System.out.println("totalPage:"+totalPage);
        System.out.println("isFirstPage:"+isFirstPage);
        System.out.println("isLastPage:"+isLastPage);
        System.out.println("prePage:"+prePage);
        System.out.println("nextPage:"+prePage);
    }

    /**
     * 设置总条目数
     * @param totalCount
     */
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getRows() {
        return rows;
    }
    /**
     * 每页显示的条数
     * @param rows
     */
    public void setRows(int rows) {
        this.rows = rows;
    }

    /**
     * 获取总页数
     * @return
     */
    public int getTotalPage() {

        return totalPage;
    }

    /**
     * 获取当前索引
     * @return
     */
    public int getStartIndex() {

        return startIndex;
    }


    /**
     * 获取当前页
     * @param
     */
    public int getCurrentPage() {
        return currentPage;
    }

    /**
     * 设置当前页
     * @param currentPage
     */
    public void setCurrentPage(int currentPage) {

        this.currentPage = currentPage;
    }

    /**
     * 是否是首页
     * @return
     */
    public boolean isFirstPage() {
        return isFirstPage;
    }


    /**
     * 是否是尾页
     * @return
     */
    public boolean isLastPage() {
        return isLastPage;
    }

    /**
     * 上一页
     * @return
     */
    public int getPrePage() {

        return prePage;
    }

    /**
     * 下一页
     * @return
     */
    public int getNextPage() {
        return nextPage2;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "totalCount=" + totalCount +
                ", rows=" + rows +
                ", totalPage=" + totalPage +
                ", currentPage=" + currentPage +
                ", isFirstPage=" + isFirstPage +
                ", isLastPage=" + isLastPage +
                ", prePage=" + prePage +
                ", nextPage=" + nextPage2 +
                ", startIndex=" + startIndex +
                '}';
    }
}
